var path = require('path'),
  webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin"),
  rucksack = require('rucksack-css'),
  autoprefixer = require('autoprefixer');
 
var OpenBrowserPlugin = require('open-browser-webpack-plugin');

var customTheme = require(path.join(__dirname, 'custom-theme.js'));

var serv_port = 8081,
  serv_doc = 'htdocs',
  publicPath = 'http://127.0.0.1:' + serv_port + '/';
  
 



module.exports = {
  entry: {
    'bundle': [
      'webpack-dev-server/client?' + publicPath, // WebpackDevServer host and port
      'webpack/hot/only-dev-server',
      path.join(__dirname, 'src', 'entry.jsx')
    ]
  },
  output: {
    filename: '[name].js'
  },
  // @@@@@@@@@@@
  babel: {
    compact: false,
    cacheDirectory: true,
    presets: [
      require.resolve('babel-preset-es2015-ie'),
      require.resolve('babel-preset-react'),
      require.resolve('babel-preset-stage-0'),
    ],
    plugins: [
      require.resolve('babel-plugin-add-module-exports'),
      require.resolve('babel-plugin-transform-decorators-legacy')
    ],
  },
  postcss: [
    rucksack(),
    autoprefixer({
      browsers: ['last 2 versions', 'Firefox ESR', '> 1%', 'ie >= 8'],
    }),
  ],
  node: {
    "child_process": "empty",
    "cluster": "empty",
    "dgram": "empty",
    "dns": "empty",
    "fs": "empty",
    "module": "empty",
    "net": "empty",
    "readline": "empty",
    "repl": "empty",
    "tls": "empty"
  },
  resolve: {
    root: [
      path.resolve(__dirname, 'src')
    ],
    alias: {
      // components is a copy of r1/components
      // antd: path.resolve(__dirname, 'components', 'antd'),
      // zipjs: path.resolve(__dirname, 'customized_modules', 'zipjs'),
      // 'ic-file-loader': path.resolve(__dirname, 'customized_modules', 'ic-file-loader')
    },
    modulesDirectories: ['node_modules', path.join(__dirname, '../node_modules')],
    extensions: ['', '.web.js', '.js', '.jsx', '.json']
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loaders: [
          'react-hot',
          'es3ify',    // Fix ie8 compatibility
          'babel'
        ]
      },
      {
        test: /\.css$/,
        loaders: [
          'style',
          'css?sourceMap&-restructuring',
          'postcss'
        ]
      },
      {
        test: /\.less$/,
        loaders: [
          'style',
          'css?sourceMap',
          'postcss',
          'less?{"sourceMap":true}'
        ]
      },
      {test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=102400&minetype=application/font-woff'},
      {test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=102400&minetype=application/font-woff'},
      {test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=102400&minetype=application/octet-stream'},
      {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file?limit=102400'},
      {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=102400&minetype=image/svg+xml'},
      {test: /\.(png|jpg|jpeg|gif|ico)(\?v=\d+\.\d+\.\d+)?$/i, loader: 'url?limit=102400'},
      {test: /\.json$/, loader: 'json'},
      {test: /\.html?$/, loader: 'file?name=[name].[ext]'}
    ]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new OpenBrowserPlugin({ url: 'http://localhost:8081/#/main/guest/home' }),
    //new webpack.NoErrorsPlugin()
  ],
  debug: true,
  devtool: 'eval-source-map',
  colors: true,
  progress: true,
  devServer: {
    hot: true,
    inline: true,
    // noInfo: false,
    historyApiFallback: true,
    contentBase: path.join(__dirname, serv_doc),
    port: serv_port
  }
}
;

